package com.example.demo.day.config.learn.design.observable.x1;

public class WeatherStation {
    private Weather mWeather;
    private Condition condition;
    private StatisticBoard statisticBoard;
    private ForecastBoard forecastBoard;

    public WeatherStation() {
        mWeather = new Weather();
        condition = new Condition();
        statisticBoard = new StatisticBoard();
        forecastBoard = new ForecastBoard();
    }

    public void onCreate() {
        mWeather.registerObserver(condition);
        mWeather.registerObserver(forecastBoard);
        mWeather.registerObserver(statisticBoard);
    }

    public void onDestroy() {
        mWeather.removeObserver(condition);
        mWeather.removeObserver(forecastBoard);
        mWeather.removeObserver(statisticBoard);
    }

    public void addBoard(Observer o) {
        mWeather.registerObserver(o);
    }

    public void removeBoard(Observer o) {
        mWeather.removeObserver(o);
    }

    public void start() {
        System.out.println("===第一次测量===");
        mWeather.serMeasurements(80,65,30.4f);
        System.out.println("===第二次测量===");
        mWeather.serMeasurements(82,70,29.2f);
        System.out.println("===第三次测量===");
        mWeather.serMeasurements(78,90,29.2f);

    }

    public static void main(String[] args) {
        WeatherStation station = new WeatherStation();
        station.addBoard(new Condition());
        //station.onCreate();
        //station.removeBoard(station.condition);
        //station.removeBoard(station.statisticBoard);
        station.start();
        station.onDestroy();
    }
}
